/**
 * @param {number[]} candidates
 * @param {number} target
 * @return {number[][]}
 */
 var combinationSum2 = function(candidates, target) {
    candidates.sort((a,b)=>a-b);
    let res=[],curr=[];
    const tools = (sum,starIndex) =>{
        if(target==sum){
            res.push([...curr])
            return
        }
        if(target<sum){
            return
        }
        for(let i=starIndex;i<candidates.length;i++){
            //去重关键代码
            if(i>starIndex&&candidates[i]==candidates[i-1]) continue
            sum+=candidates[i]
            curr.push(candidates[i])
            tools(sum,i+1)
            sum-=candidates[i]
            curr.pop()
        }
    }
    tools(0,0)
    return res
};
console.log(combinationSum2([10,1,2,7,6,1,5],8));